package com.qf.sevice.Impl;

import com.qf.dao.GoodsDao;
import com.qf.dao.Impl.GoodsDaoImpl;
import com.qf.domain.Goods;
import com.qf.domain.GoodsType;
import com.qf.domain.PageBean;
import com.qf.sevice.GoodsService;
import com.qf.sevice.GoodsTypeService;

import java.util.Date;
import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    GoodsDao goodsDao = new GoodsDaoImpl();
    @Override
    public PageBean findByPage(int typeId, int pageNum, int pageSize) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pageNum);
        pageBean.setPageSize(pageSize);
        //查询总条数
        long totalCount = goodsDao.findTotalCount(typeId);
        pageBean.setTotalCount(totalCount);
        // limit m,n; m:起始索引 ,n:每页条数
        //每页5条  第一页：limit 0,5;  第二页：5,5  第三页： 10,5 第四页；15，5
        List<Goods> list = goodsDao.findData(typeId, (pageNum - 1) * pageSize , pageSize);
        pageBean.setData(list);
        return pageBean;
    }

    @Override
    public Goods findById(int id) {
        Goods goods=goodsDao.findById(id);
        GoodsTypeService typeService = new GoodsTypeServiceImpl();
        GoodsType goodsType=typeService.findById(goods.getTypeid());
        goods.setGoodsType(goodsType);
        return goods;
    }

    @Override
    public List<Goods> findAllGoods() {
        return goodsDao.findAllGoos();
    }

    @Override
    public void addGoods(Goods goods) {
        goodsDao.addGoods(goods);
    }

    @Override
    public void update(String name, double price, String time, int typeid, String info, int id) {
        goodsDao.update(name,price,time,typeid,info,id);
    }


}
